<?php
	class CustomerController extends BaseController{
		public function getSelect($shop_id){
			try{
					echo $json = json_encode(Customers::Select($shop_id));
			}
			catch(Exception $e){
				return ErrorResponse::SendErrorMessage($e->getMessage());
			}
		}
		public function postRegister(){
	    	//checks the information input
		    try{
            $input=Input::json()->all();

            $shop_id=InputHelper::getInput($input,'shop_id');

            $name=InputHelper::getInput($input,'name');

            $address=InputHelper::getInput($input,'address');

            $phone=InputHelper::getInput($input,'phone');

            $email=InputHelper::getInput($input,'email','');

            $comments=InputHelper::getInput($input,'comments','');

            $gender=InputHelper::getInput($input,'gender','');
			}
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        } 
	        // insert to database 
		    try{
		    	
		    	if($customer_id = Customers::Insert($name,$address,$phone,$email,$comments,$gender,$shop_id))
	        	{
                	return Response::json(array('status'=>'success','customer_id'=>$customer_id));
                //	return (Users::Insert_accounts($username,$password,$staff_id));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		}
                
        
        public function postEdit(){
	    	//checks the information input
		   try{
            $input=Input::json()->all();

            $customer_id=InputHelper::getInput($input,'customer_id');

            $name=InputHelper::getInput($input,'name');

            $address=InputHelper::getInput($input,'address');

            $phone=InputHelper::getInput($input,'phone');

            $email=InputHelper::getInput($input,'email','');

            $comments=InputHelper::getInput($input,'comments','');

			}
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        } 
		    try{
		    	
   	 		if(Customers::Edit($name,$address,$phone,$email,$comments,$customer_id))
	        	{
	        	
                	return Response::json(array('status'=>'success'));
                }
                
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }

         
         }
         

         public function postDelete($customer_id){
	        try{
	        	if(Customers::Del($customer_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}	             
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    
	}
 }
?>